<?php

namespace App\Http\Middleware;

use Closure;

class Cross
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     * 跨域中间件
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        $response->headers->add([
            'Access-Control-Allow-Origin'=> '*',
            'Access-Control-Allow-Headers'=> 'Origin, Content-Type, Cookie, Accept,Authorization',
            'Access-Control-Allow-Methods'=>'GET, POST, PATCH, PUT, OPTIONS,DELETE',
            //'Access-Control-Allow-Credentials'=>'true'
        ]);

        /*
             这样写会和laravel-wechat 造成冲突'
          $response->header('Access-Control-Allow-Origin', '*');
             $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Cookie, Accept, multipart/form-data, application/json,Authorization');
             $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS,DELETE');
             $response->header('Access-Control-Allow-Credentials', 'true');*/
        return $response;
    }
}